#include "CyGUIText.h"
#include "CyRoutine.h"
using namespace std;

CyGUIText::CyGUIText(HWND parentHWND, INT id)
{
	_id = id;
	_hwnd = GetDlgItem(parentHWND, id);
	if (_hwnd == 0)
	{
		CY_THROW("Cannot find the text");
	}
}

CyGUIText::~CyGUIText(void)
{
}

void CyGUIText::SetText(const std::wstring& str)
{
	SetWindowText(_hwnd, str.c_str());
}

wstring& CyGUIText::GetText(wstring& str) const
{
	UINT l = GetWindowTextLength(_hwnd);
	WCHAR* buffer = new WCHAR[l+1];
	GetWindowText(_hwnd, buffer, l+1);
	str = buffer;
	delete []buffer;
	return str;
}